opencv2.4
1.Install Dependency
yum install -y install epel-release gcc gcc-c++ python-devel numpy gtk2-devel libdc1394-devel libv4l-devel gstreamer-plugins-base-devel


2.Install ffmpeg

CentOS 6比较简单，安装yum源之后直接安装即可：

su -c 'yum localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-6.noarch.rpm https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-6.noarch.rpm'

yum -y install ffmpeg ffmpeg-devel

而CentOS 7需额外安装扩展源：

su -c 'yum localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm'

rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm

yum -y install ffmpeg ffmpeg-devel

3.Install opencv

cd opencv
mkdir build
cd build

#如需指定GCC版本
在CMakeLists.txt 增加

SET(CMAKE_C_COMPILER “/usr/local/gcc-5.5/bin/gcc”)
SET(CMAKE_CXX_COMPILER “/usr/local/gcc-5.5/bin/g++”)
以上如不行，使用下面：
vi /etc/profile
//使用特定版本的gcc
export CC=/usr/local/bin/gcc
export CXX=/usr/local/bin/g++

opencv2.4 + cuda 9 
https://github.com/davidstutz/opencv-2.4-cuda-9-patch/tree/master/cmake
https://cloud.tencent.com/developer/article/1367603

export CUDA_npp_LIBRARY=/usr/local/cuda-9.0/lib64

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local/opencv ..
#如果报GPU错误：
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv2 -D CUDA_GENERATION=Kepler ..

or
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv2 -D CUDA_GENERATION=Kepler CUDA_NVCC_FLAGS="-ccbin gcc-4.9"

or:
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local/opencv2 -D BUILD_TIFF=ON -D BUILD_EXAMPLES=ON -D CUDA_GENERATION=Auto -D BUILD_NEW_PYTHON_SUPPORT=ON ..

#不使用CUDA的编译版本，在出现opencv_dep_CUDA_nppi_LIBRARY找不到的时候使用

cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D INSTALL_C_EXAMPLES=OFF \
    -D OPENCV_EXTRA_MODULES_PATH=~/Desktop/opencv_contrib-3.1.0/modules \
    -D PYTHON_EXECUTABLE=~/py2virtualenv/opencvcv/bin/python \
    -D WITH_CUDA=OFF \
    -D BUILD_EXAMPLES=ON ..

#Or
cmake ..
make
make install